<?php

/**
 * Controlador genérico que encapsula funciones genéricas
 * 
 * @author grover
 * @version 0.1
 * @package Gtux
 * @subpackage Controller
 *
 */
class Gtux_Controller_Action extends Zend_Controller_Action
{
  /**
   * @var Zend_Auth
   */
  protected $_auth;
  /**
   * @var Zend_Auth_Adapter_DbTable
   */
  protected $_authAdapter;
  /**
   * @var Zend_Db_Adapter_Mysqli
   */ 
  protected $_db;
  /**
   * @var Zend_Log
   */
  protected $_logger;
  /**
   * @var Zend_Session_Namespace
   */
  protected $_session;
  
  /**
   * @see Zend_Controller_Action::init()
   *
   */
  public function init()
  {
    // leo el bootstrap
    $bootstrap = $GLOBALS['application']->getBootstrap();
    $dbAdapter = $bootstrap->getResource('db');
    $this->_logger = Zend_Registry::get('logger');
    // inicializo el Zend_Auth
    $this->_authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter, 'users', 'username', 'password', 'MD5(?)');
    $this->_auth = Zend_Auth::getInstance();
    $this->_auth->setStorage(new Zend_Auth_Storage_Session(Zend_Registry::get('ns')));
    
    // Inicializo las variables
    $ns = new Zend_Session_Namespace(Zend_Registry::get('ns'));
    if (!$ns->variables instanceof ArrayObject)
    {
      $variable = new Gtux_Model_Variable();
      $coll     = new ArrayObject($variable->fetchAll());
      $ns->variables = $coll;
    }
    $this->_session = $ns;
  }

}

?>